package cn.home.fenni.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.home.common.annotation.Log;
import cn.home.common.core.controller.BaseController;
import cn.home.common.core.domain.AjaxResult;
import cn.home.common.enums.BusinessType;
import cn.home.fenni.domain.HomeServicePackage;
import cn.home.fenni.service.IHomeServicePackageService;
import cn.home.common.utils.poi.ExcelUtil;
import cn.home.common.core.page.TableDataInfo;

/**
 * 服务包Controller
 * 
 * @author homedoctor
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/package/package")
public class HomeServicePackageController extends BaseController
{
    @Autowired
    private IHomeServicePackageService homeServicePackageService;

    /**
     * 查询服务包列表
     */
    @PreAuthorize("@ss.hasPermi('package:package:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomeServicePackage homeServicePackage)
    {
        startPage();
        List<HomeServicePackage> list = homeServicePackageService.selectHomeServicePackageList(homeServicePackage);
        return getDataTable(list);
    }

    /**
     * 导出服务包列表
     */
    @PreAuthorize("@ss.hasPermi('package:package:export')")
    @Log(title = "服务包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomeServicePackage homeServicePackage)
    {
        List<HomeServicePackage> list = homeServicePackageService.selectHomeServicePackageList(homeServicePackage);
        ExcelUtil<HomeServicePackage> util = new ExcelUtil<HomeServicePackage>(HomeServicePackage.class);
        util.exportExcel(response, list, "服务包数据");
    }

    /**
     * 获取服务包详细信息
     */
    @PreAuthorize("@ss.hasPermi('package:package:query')")
    @GetMapping(value = "/{packageId}")
    public AjaxResult getInfo(@PathVariable("packageId") Long packageId)
    {
        return success(homeServicePackageService.selectHomeServicePackageByPackageId(packageId));
    }

    /**
     * 新增服务包
     */
    @PreAuthorize("@ss.hasPermi('package:package:add')")
    @Log(title = "服务包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomeServicePackage homeServicePackage)
    {
        return toAjax(homeServicePackageService.insertHomeServicePackage(homeServicePackage));
    }

    /**
     * 修改服务包
     */
    @PreAuthorize("@ss.hasPermi('package:package:edit')")
    @Log(title = "服务包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomeServicePackage homeServicePackage)
    {
        return toAjax(homeServicePackageService.updateHomeServicePackage(homeServicePackage));
    }

    /**
     * 删除服务包
     */
    @PreAuthorize("@ss.hasPermi('package:package:remove')")
    @Log(title = "服务包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{packageIds}")
    public AjaxResult remove(@PathVariable Long[] packageIds)
    {
        return toAjax(homeServicePackageService.deleteHomeServicePackageByPackageIds(packageIds));
    }

    @GetMapping("/tags/{packageId}")
    public List<String> getTagsByPackageId(@PathVariable Long packageId) {
        return homeServicePackageService.getTagsByPackageId(packageId);
    }
}
